home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / bat.zip / BATSTK.ASM < prev    next >
Assembly Source File  |  1985-10-16  |  17KB  |  358 lines

  1.          PAGE  60,132
  2.          TITLE BATSTACK -- Special device driver for EBL keyboard stack
  3.          COMMENT $
  4.  
  5.          BATSTACK                 Nathaniel R. Goodspeed
  6.  
  7. --------
  8. Overview
  9. --------
  10. This device driver supports the "keyboard stack" available through use of the
  11. Extended Batch Language, EBL.  Normally, the only way to get stuff into the
  12. keyboard stack is to use the EBL commands STACK or BEGSTACK ... END.  (Programs
  13. remove entries from the stack by attempting normal keyboard reads, and EBL
  14. provides a way to read the stack into EBL variables.)  But BATSTACK allows the
  15. output of any program to be produced into the stack, using normal DOS output
  16. redirection:
  17.  
  18. echo This is going into the keyboard stack>batstack
  19.  
  20. Obviously, the use of STACK or BEGSTACK is better than ECHOing into BATSTACK.
  21. But the power of BATSTACK is that any filter can produce output into the 
  22. keyboard stack, for use by any other program, or for further processing by
  23. EBL programs.  
  24.  
  25. ------------
  26. Installation
  27. ------------
  28. BATSTACK is created by assembling BATSTK.ASM, linking it, and converting it
  29. to a .COM-form file with the extension .DEV (so nobody tries to execute it
  30. by typing its name, which would result in chaos).
  31.          masm batstk,batstk,batstk,nul;
  32.          link batstk;
  33.          exe2bin batstk.exe batstk.dev
  34.          del batstk.obj
  35.          del batstk.exe
  36.  
  37. Once you have BATSTK.DEV, it is installed by adding a line to your CONFIG.SYS 
  38. file of the form:
  39.          DEVICE=BATSTK.DEV
  40. You must either ensure that BATSTK.DEV is in the root directory of your boot
  41. disk, or supply the full drive and pathname of its location, e.g.:
  42.          DEVICE=C:\DEVICES\BATSTK.DEV
  43. BATSTACK will be installed when the system is next rebooted.  It will announce
  44. its presence with the message "BATSTACK driver loaded."
  45.  
  46. You may be wondering why, since the device is called BATSTACK, the files used
  47. to implement it are called BATSTK.* .  The reason is that once a device with
  48. a particular name is installed in your system, DOS ignores any extension given
  49. with that device name!  In other words, if the BATSTACK source and device files
  50. were named BATSTACK.ASM and BATSTACK.DEV, DOS would forget that the disk files
  51. were there as soon as the BATSTACK device was installed.  The command line
  52. "type batstack.asm" would be treated the same as "type batstack", and would 
  53. cause the contents of the stack to be typed!  (This is why it's not possible
  54. to create a disk file called CON.TXT, too.)
  55.  
  56. -----------
  57. Usage Notes
  58. -----------
  59. There are two cases in which you might want to redirect a filter's output to
  60. BATSTACK rather than a file or pipe.  The first to let an EBL batch file
  61. read the output, so that (for instance) a batch file can know a file's size
  62. without having to display DIR output on the screen and find it using READSCRN.
  63.  
  64. The second case is when you want the filter to supply some, but not all, of
  65. the input for a program to follow.  When a program thinks it's reading the
  66. keyboard, it will read the stack until it is exhausted, then revert to reading 
  67. the real keyboard.  So to supply the first few commands for program2 from 
  68. program1, you could place in a batch file the lines:
  69.          program1 >batstack
  70.          program2
  71. By contrast, if you connect the two programs with a DOS pipeline:
  72.          program1 | program2
  73. or redirect the output of the first into a file, and read that with the second:
  74.          program1 >miscfile
  75.          program2 <miscfile
  76. then program1 had better generate an explicit command to cause program2 to 
  77. terminate, or else program2 might reach end-of-file on the pipeline or file and
  78. wait indefinitely for a termination command to appear, without allowing it to
  79. be typed from the real keyboard!  If program2 is itself a filter, or at any
  80. rate was coded to recognize end-of-file on standard input, it will terminate at
  81. end-of-file.  But in no case will it automatically switch to the real keyboard.
  82.  
  83. Don't try to copy a large amount of text into BATSTACK, however.  The EBL 2.04a
  84. stack handler apparently isn't very careful about checking for stack-full, at
  85. least not when text is entered with the INT 16H, AH=73H option.  Not only is
  86. there no defined way to detect a stack-full condition on return from the INT,
  87. but when I attempted to copy a 537-byte file into a stack initialized with the
  88. usual BAT * 512 command, the ctrl-PrtSc key stopped working!  (DOS echoed ^P
  89. at the command prompt rather than echoing following characters to the printer.)
  90.  
  91. --------------------
  92. Implementation Notes
  93. --------------------
  94. The Extended Batch Language STACK and BEGSTACK commands normally delimit each
  95. line in the stack with a CR, rather than a CR/LF as DOS text lines normally end.
  96. This is consistent with the pretext that the stack contains user keystrokes;
  97. the user never types an explicit LF.  However, since the BATSTACK driver is
  98. expected to handle normal DOS text files, it performs a transformation:  when
  99. CR/LF is written to BATSTACK, the LF is discarded; when CR is read from BATSTACK,
  100. an LF is automatically appended.  In theory, unless the text written to BATSTACK
  101. already contains CR characters without LFs, this should be transparent if the
  102. BATSTACK driver is both written and read by DOS:
  103.          copy myfile batstack
  104.          copy batstack myfile.new
  105. But when the stack is read via keyboard requests, no spurious LFs will show up.
  106.  
  107. Another funny convention followed by BATSTACK when being read as a DOS device
  108. is that there is always a character ready to be read -- but if the stack is 
  109. empty or disabled, the character returned by BATSTACK will be a simulated 
  110. ctrl-Z, to cause DOS programs to recognize end-of-file.  The DOS device driver 
  111. documentation suggests that if a driver sets the "busy" bit meaning that no 
  112. character is currently available, DOS will wait under some circumstances until 
  113. the "busy" bit is reset.  We can be almost positive, however, that if the stack 
  114. is empty or disabled, no new characters will appear in it no matter how long 
  115. DOS might wait.  This is why we always claim that we have a character ready.
  116.  
  117. A useful enhancement to the EBL INT 16H stack support would be a status return 
  118. on functions 73H and 74H, so programs could tell if the write failed.  Another
  119. would be a function to request the current stack enable/disable status and the
  120. length of the current contents.  This would let programs specifically interes-
  121. ted in the stack, not the keyboard, read it even if it were disabled, saving 
  122. and restoring the user's enable/disable state.
  123.  
  124. NRG 09/05/85
  125. $
  126.          PAGE
  127. MYSTACKSIZE EQU 256               ;DOS MANUAL CLAIMS DEVICE DRIVERS NEED OWN STACK
  128. LF       EQU   0AH                ;LINE-FEED CHARACTER
  129. CR       EQU   0DH                ;CARRIAGE-RETURN CHARACTER
  130. EOF      EQU   1AH                ;CTRL-Z IS END-OF-FILE MARKER
  131.  
  132. LJZ      MACRO DEST
  133.          LOCAL NZDEST
  134.          JNZ   NZDEST
  135.          JMP   DEST
  136. NZDEST:
  137.          ENDM
  138.  
  139. DEVATTR  RECORD DEVCHAR:1=0, DEVIOCTL:1=0, DEVNONIBM:1=0, UNUSED:9=0, DEVCLOCK:1=0, DEVNUL:1=0, DEVSTDOUT:1=0, DEVSTDIN:1=0
  140.  
  141. DUMMY    STRUC
  142. WORDSIZE DW    ?
  143. DUMMY    ENDS
  144.  
  145. ;        DEVICE HEADER
  146.  
  147. CSEG     SEGMENT BYTE PUBLIC 'CODE'
  148.          DD    -1                 ;REQUIRED; WILL BECOME PTR TO NEXT DRIVER
  149.          DEVATTR <1,0>            ;DEVICE ATTRIBUTES: CHAR, NO IOCTL SUPPORT
  150.          DW    OFFSET STRATEGY    ;PTR TO DEVICE STRATEGY ROUTINE
  151.          DW    OFFSET INTERRUPT   ;PTR TO DEVICE INTERRUPT ROUTINE
  152.          DB    'BATSTACK'         ;DEVICE NAME -- BETTER BE DIFFERENT FROM
  153.                                   ;OUR SOURCE, BINARY ETC. OR WE CAN'T ACCESS
  154.                                   ;DISK FILES ONCE IT'S INSTALLED!
  155.  
  156. REQHDR   DD    ?                  ;SAVE REQUEST HEADER PTR HERE
  157. MYSP     DW    -2                 ;FIRST CALL, SET SP ALMOST AS HIGH AS CAN REACH
  158.                                   ;(FOR INIT, WE HAVE ALL OF MEMORY TO OURSELVES)
  159. OLDSP    DW    ?                  ;SAVE DOS SP/SS HERE
  160. OLDSS    DW    ?
  161. LASTREAD DB    00H                ;LAST CHARACTER READ FROM STACK
  162. LASTWRITE DB   00H